package bc.running.forum.db.translators;

import java.io.BufferedReader;
import java.sql.Clob;
import java.sql.SQLException;

public class ClobDataTranslator implements IDataTranslator {

	public Object translate(Object src)  throws Exception {
		if(src == null) {
			return null;
		}
		if(!(src instanceof Clob)) {
			throw new RuntimeException(src.getClass()+  " is not a Clob");
		}
		Clob clob = (Clob)src;
		long len = clob.length();
		if(len == 0) {
			return "";
		}
		StringBuilder builder = new StringBuilder();
		BufferedReader reader = new BufferedReader(clob.getCharacterStream());
		String tmp;
		while ((tmp = reader.readLine())!= null) {
			builder.append(tmp);
		}
		return builder.toString();
	}

}
